﻿/****************************************************************************
**		File: ORelationTransfer.cs
** 		Desc: 微信-组织关系转移
** 		Called by:
**
** 		Auth: 陈泳江 （chenyongjiang@sxt.com.cn）
** 		Date: 2014/5/12 14:12:47
** ===========================================================================
** 		Change History
** ===========================================================================
** 		Date:		Author:				Description:
** 		--------	--------			-------------------
**
** ===========================================================================
** Copyright (C) 2004-2011 SXT Corporation
******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient; 
using System.IO;
using System.Text; 

namespace ZHDJ.MobileInterface.Common
{
    public class ORelationTransfer
    {
        //#region 组织关系转移

        //#region  填写接口
        //public static string ORTransfer(string LoginID, string Explain, string TageBranchID, int Age, string FromBranchAddress,
        //    string FromBranchFax, string FromBranchMobileNo, string FromBranchZip, string SerialNumber = "")
        //{
        //    //检查是否已经申请过
        //    if (CheckHasApply(LoginID))
        //    { return "你已经申请了一次组织关系转移,不能重复申请！"; }

        //    //编号
        //    string SerialNumberEx = string.Empty;
        //    if (string.IsNullOrEmpty(SerialNumber))
        //    {
        //        SerialNumberEx = GetSerialNumber();
        //    }
        //    else { SerialNumberEx = SerialNumber; }

        //    //检查是否存在相同编号
        //    if (CheckSerialNumber(SerialNumberEx))
        //    { return "已存在相同的编号，请确认后再重试"; }

        //    string ID = StringHelper.NewID;

        //    //获取组织ID，用户名
        //    string sqlGetBranchID = string.Format(@" select BranchID,UserName from tblPartyOrgMembers where LoginID='{0}'", LoginID);
        //    DataTable dt = DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(sqlGetBranchID).Tables[0];
        //    #region
        //    if (dt.Rows.Count > 0)
        //    {
        //        //党费最后缴纳日期
        //        string MemberCostTime = GetMemberCostDate(LoginID);

        //        string FormerBranchID = dt.Rows[0]["BranchID"].ToString();
        //        string UserName = dt.Rows[0]["UserName"].ToString();

        //        string sql1 = string.Format(@" insert into 
        //                        tblPartyRelationshipTransfer(ID,Explain,TageBranchID,Applicant,CreateTime,Status,FormerBranchID,Age,
        //                        FromBranchAddress,FromBranchFax,FromBranchMobileNo,MemberCostTime,FromBranchZip,SerialNumber,ValidTime)
        //                        values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')"
        //                         , ID, Explain, TageBranchID, LoginID, DateTime.Now, "审批中", FormerBranchID, Age, FromBranchAddress, FromBranchFax
        //                         , FromBranchMobileNo, MemberCostTime, FromBranchZip, SerialNumberEx, 1);

        //        string sql2 = string.Format(@" exec sp_RelationshipTransfer_Branch '{0}'", ID);

        //        string ID2 = string.Empty;
        //        ID2 = StringHelper.NewID;
        //        string sql3 = string.Format(@" insert into tblPartyProcessesResume(ID,ApplyID,Approver,Explain,
        //                                ApprovalResult,CreateTime,StepInfo) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", ID2, ID,
        //                                                                                                  LoginID, Explain, "提交申请", DateTime.Now, "1");

        //        DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(sql1);
        //        DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(sql2);
        //        DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(sql3);
        //        string[] approval = new string[] { FormerBranchID };
        //        InterfaceHelper.AddTask(ID, UserName + "组织关系转移申请",
        //            "组织转移申请", LoginID,
        //           approval,
        //           CommonUtils.AppAddress + "/Widgets/Pages/MyHomePage/RelationshipTransferApproval.aspx?RelationID=" + ID
        //           , "Branch");
        //        return "";
        //    }
        //    else
        //    {
        //        return "该用户不存在资料库中！";
        //    }
        //    #endregion
        //    //return "";
        //}



        //public static void AddRelationshipBranch(string id)
        //{
        //    using (SqlCommand cmd = new SqlCommand())
        //    {
        //        StringBuilder sbSql = new StringBuilder();
        //        sbSql.Append(@" exec sp_RelationshipTransfer_Branch @ID ");
        //        cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = id;
        //        cmd.CommandText = sbSql.ToString();
        //        DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(cmd);
        //    }
        //}

        ///// <summary>
        ///// 获取最后党费缴纳日期
        ///// </summary>
        ///// <param name="loginID"></param>
        ///// <returns></returns>
        //public static string GetMemberCostDate(string loginID)
        //{
        //    using (SqlCommand cmd = new SqlCommand())
        //    {
        //        StringBuilder sbSql = new StringBuilder();
        //        sbSql.Append(@"  select top 1 cast(YEAR AS nvarchar(10))+'-'+cast(Month AS nvarchar(10)) as PayDate from tblPartyMemberCost mc 
        //                            inner join tblPartyOrgMembers om on mc.LoginID=om.LoginID
        //                            where PayDate is not null and mc.LoginID=@LoginID
        //                            order by Month desc ");
        //        cmd.Parameters.Add("@LoginID", SqlDbType.VarChar).Value = loginID;
        //        cmd.CommandText = sbSql.ToString();
        //        object obj = DB.DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteScalar(cmd);
        //        if (obj != null && obj.ToString() != "")
        //            return Convert.ToDateTime(obj).ToString("yyyy-MM");
        //        else
        //            return "";
        //    }
        //}

        ///// <summary>
        ///// 获取序列号
        ///// </summary>
        ///// <param name="loginID"></param>
        ///// <returns></returns>
        //public static string GetSerialNumber()
        //{
        //    using (SqlCommand cmd = new SqlCommand())
        //    {
        //        StringBuilder sbSql = new StringBuilder();
        //        sbSql.Append(@"  select Count(1) from tblPartyRelationshipTransfer ");
        //        cmd.CommandText = sbSql.ToString();
        //        object obj = DB.DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteScalar(cmd);
        //        if (obj != null && obj.ToString() != "")
        //            return (Convert.ToInt32(obj) + 1).ToString("D8");
        //        else
        //            return "00000001";
        //    }
        //}

        ///// <summary>
        ///// 检查是否已经申请
        ///// </summary>
        ///// <param name="loginID"></param>
        ///// <returns></returns>
        //public static bool CheckHasApply(string loginID)
        //{
        //    using (SqlCommand cmd = new SqlCommand())
        //    {
        //        StringBuilder sbSql = new StringBuilder();
        //        sbSql.Append(@"  select COUNT(*) from tblPartyRelationshipTransfer where Applicant = @Applicant and Status='审批中'");
        //        cmd.Parameters.Add("@Applicant", SqlDbType.VarChar).Value = loginID;
        //        cmd.CommandText = sbSql.ToString();
        //        return Convert.ToInt32(DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteScalar(cmd)) > 0;
        //    }
        //}

        ///// <summary>
        ///// 检查是否存在相同编号
        ///// </summary>
        ///// <param name="serialNumber"></param>
        ///// <returns></returns>
        //public static bool CheckSerialNumber(string serialNumber)
        //{
        //    using (SqlCommand cmd = new SqlCommand())
        //    {
        //        StringBuilder sbSql = new StringBuilder();
        //        sbSql.Append(@"  select COUNT(*) from tblPartyRelationshipTransfer where SerialNumber = @SerialNumber ");
        //        cmd.Parameters.Add("@SerialNumber", SqlDbType.VarChar).Value = serialNumber;
        //        cmd.CommandText = sbSql.ToString();
        //        return Convert.ToInt32(DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteScalar(cmd)) > 0;
        //    }
        //}
        //#endregion

        //#endregion
    }
}